package com.lehecai.core.api.business;

import com.lehecai.core.IntegerBeanLabelItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangzq on 14-9-1.
 */
public class AreaType extends IntegerBeanLabelItem {

    private static final Logger logger = LoggerFactory.getLogger(AreaType.class.getName());

    private static List<AreaType> items = new ArrayList<AreaType>();
    private static List<AreaType> queryItems = new ArrayList<AreaType>();

    protected AreaType(String name, int value, boolean queryOnly) {
        super(AreaType.class.getName(), name, value);

        queryItems.add(this);
        if (!queryOnly) {
            items.add(this);
        }
    }

    protected AreaType(String name, int value) {
        this(name, value, false);
    }

    public static AreaType getItem(int value){
        try {
            return (AreaType) AreaType.getResult(AreaType.class.getName(), value);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static List<AreaType> getItems() {
        return items;
    }

    public static List<AreaType> getItemsForQuery() {
        return queryItems;
    }

    public static final AreaType ALL = new AreaType("全部", 0, true);
    public static final AreaType AREA_TYPE_NORTH = new AreaType("north", 1);
    public static final AreaType AREA_TYPE_SOUTH = new AreaType("south", 2);
    public static final AreaType AREA_TYPE_OTHER = new AreaType("other", 3);
}
